package com.problem.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author didi
 * @DESCRIPTION
 * @create 2019-05-15 13:28
 **/

public class Problem448 {
    public List<Integer> findDisappearedNumbers(int[] nums) {
        Arrays.sort(nums);
        int           count       = 1;
        int           lastElement = -1;
        List<Integer> list        = new ArrayList<>(nums.length);
        for (int index = 0; index < nums.length; index++) {
            if (index == 0) {
                lastElement = nums[index];

                if(count != nums[index]) {
                    list.add(count);
                    count = nums[index];
                }

            } else {
                if (nums[index] != lastElement) {
                    if (nums[index] != ++count) {
                        for (int tmpIndex = count; tmpIndex < nums[index]; tmpIndex++) {
                            list.add(tmpIndex);
                        }
                        count = nums[index];
                    }
                }
                lastElement = nums[index];
            }
        }
        return list;
    }
}
